package com.lc.YYGH.hosp.controller;

import com.alibaba.excel.util.StringUtils;
import com.lc.YYGH.common.result.Result;
import com.lc.YYGH.helper.HttpRequestHelper;
import com.lc.YYGH.hosp.service.LawerService;
import com.lc.YYGH.hosp.service.OfficeService;
import com.lc.YYGH.hosp.service.ProfessionService;
import com.lc.YYGH.model.hosp.Department;
import com.lc.YYGH.model.hosp.Hospital;
import com.lc.YYGH.model.hosp.Schedule;
import com.lc.YYGH.model.office.LawOffice;
import com.lc.YYGH.model.office.Lawer;
import com.lc.YYGH.model.office.Profession;
import com.lc.YYGH.vo.hosp.DepartmentQueryVo;
import com.lc.YYGH.vo.hosp.ScheduleQueryVo;
import com.lc.YYGH.vo.office.LawerQueryVo;
import com.lc.YYGH.vo.office.ProfessionQueryVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.Map;

@Api(tags="事务所管理接口")
@RestController
@RequestMapping("/api/office")
public class OfficeController {
    @Autowired
    private OfficeService officeService;
    @Autowired
    private LawerService lawerService;
    @Autowired
    private ProfessionService professionService;
    @PostMapping("saveOffice")
    public Result save(HttpServletRequest request)
    {
        Map<String,String[]> parameterMap=request.getParameterMap();
        Map<String,Object> map= HttpRequestHelper.switchMap(parameterMap);
        officeService.save(map);
        return Result.success();
    }
    @ApiOperation(value="获取事务所信息")
    @PostMapping("show")
    public Result findOffice(HttpServletRequest request)
    {
        Map<String, String[]> parameterMap = request.getParameterMap();
        Map<String,Object> map=HttpRequestHelper.switchMap(parameterMap);
        String code=(String)map.get("officecode");
        System.out.println("------------"+code);
        LawOffice lawOffice=officeService.findOffice(code);
        return Result.success(lawOffice);

    }

    @ApiOperation(value="添加律师")
    @PostMapping("saveLawer")
    public Result saveLawer(HttpServletRequest request)
    { Map<String, String[]> parameterMap = request.getParameterMap();
      Map<String,Object> map=HttpRequestHelper.switchMap(parameterMap);
      lawerService.save(map);
      return Result.success();

    }
    @PostMapping("saveProfession")
    public Result saveSchedule(HttpServletRequest request)
    {
        Map<String, String[]> parameterMap = request.getParameterMap();
        Map<String,Object> map=HttpRequestHelper.switchMap(parameterMap);
        String hoscode=(String)map.get("hoscode");
        //验证签名key
        professionService.save(map);
        return Result.success();
    }
    @PostMapping("lawer/list")
    public Result findDepartmentsByPage(HttpServletRequest request)
    {
        Map<String, String[]> parameterMap = request.getParameterMap();
        Map<String,Object> map=HttpRequestHelper.switchMap(parameterMap);
       // String hoscode=(String)map.get("hoscode");
        String lawercode=(String)map.get("lawercode");
        //签名校验
        //页号
        Integer page = StringUtils.isEmpty(map.get("page")) ? 1 :
                Integer.parseInt((String) map.get("page"));
        //每页数据条数
        Integer limit = StringUtils.isEmpty(map.get("limit")) ? 10 :
                Integer.parseInt((String) map.get("limit"));
        LawerQueryVo lawerQueryVo=new LawerQueryVo();
     //   DepartmentQueryVo dVo=new DepartmentQueryVo();
        lawerQueryVo.setOfficecode(lawercode);
        //dVo.setHoscode(hoscode);
        Page<Lawer> pageModel1= lawerService.findPageLawer(page,limit,lawerQueryVo);
        return Result.success(pageModel1);

    }

    @PostMapping("lawer/remove")
    public Result removeDepartment(HttpServletRequest request)
    {
        Map<String, String[]> parameterMap = request.getParameterMap();
        Map<String,Object> map=HttpRequestHelper.switchMap(parameterMap);
        String lawercode=(String)map.get("lawercode");
        String officecode=(String)map.get("officecode");
        //签名校验(同签名)、
        lawerService.removeLawer(lawercode,officecode);
        return Result.success();

    }
    @PostMapping("profession/remove")
    public Result removeProfession(HttpServletRequest request)
    {
        Map<String, String[]> parameterMap = request.getParameterMap();
        Map<String,Object> map=HttpRequestHelper.switchMap(parameterMap);
        String lawercode=(String)map.get("lawercode");
        String professioncode=(String)map.get("professioncode");
        //签名校验(同签名)、
        professionService.removeProfession(lawercode,professioncode);
        return Result.success();

    }







    @PostMapping("profession/list")
    public Result findProfession(HttpServletRequest request)
    {
        Map<String, String[]> parameterMap = request.getParameterMap();
        Map<String,Object> map=HttpRequestHelper.switchMap(parameterMap);
        Integer page = StringUtils.isEmpty(map.get("page")) ? 1 :
                Integer.parseInt((String) map.get("page"));
        //每页数据条数
        Integer limit = StringUtils.isEmpty(map.get("limit")) ? 10 :
                Integer.parseInt((String) map.get("limit"));

      //  ScheduleQueryVo scheduleQueryVo=new ScheduleQueryVo();
        ProfessionQueryVo professionQueryVo=new ProfessionQueryVo();

        Page<Profession> pageModel1= professionService.selectPage(page,limit,professionQueryVo);
        return Result.success(pageModel1);
    }

}

